package Runde5;


public class PreorderTree<A extends Comparable<? super A>> extends SortedTree<A> {
	
	/**
	 * @precondition root != null
	 * @postcondition Creates a new binary search tree with the root labeled by the given object and traversed by the order specified in its name (e.g. "InorderTree").
	 */
	public PreorderTree(A root) {
		super(root);
	}
	
	/**
	 * @precondition The node has to be the root of the tree to traverse (and therefore may not be null).
	 * @postcondition Adds the nodes of the node's subtree to a list recursively. The order is specified in the name (e.g. "InorderTree").
	 */
	protected void addNodesToList(Node node, List<A> list) {
		list.add(node.getLabel());
		
		if (!(node.getLeftChild() == null)) {
			addNodesToList(node.getLeftChild(), list);
		}
		
		if (!(node.getRightChild() == null)) {
			addNodesToList(node.getRightChild(), list);
		}
	}
	
}